home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!sun2!ua302aa
- From: ua302aa@sun2.lrz-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: What is '?' in C mean....?????
- Date: 4 Jan 1996 19:28:33 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4ch9p1$kfq@sparcserver.lrz-muenchen.de>
- References: <4cgsa8$bm2@wumpus.cc.uow.edu.au> <fcusack-0401961115540001@mudskipper.cac.psu.edu>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- fcusack@tdx.org (frank.) writes:
-
- >> Could anyone here explain to me what is "?" means and what the purpose
- >>of using
-
- >You can probably find this info in the FAQ!!!!
-
- >? : is C's ternary operator. if the condition is met, perform the
- >operation after the ?; if the condition is not met, perform the operation
- >after the :
-
- Replace "perform operation" with "evaluate expression", and I'll
- agree with you. If evaluating the expression has any side effects,
- and if the result of the conditional expression is not used, the
- net effect will be pretty much the same, but this does not explain
- the differenct between
-
- if (foo()) bar(); else baz();
-
- and
-
- boo = foo() ? bar() : baz();
-
- The conditional expression is an _expression_, not just an obfuscated
- way to write a certain control flow statement.
-
- Consider the following function called Abs() for more than one reason:
-
- int Abs(int x)
- {
- return x < 0 ? -x : x;
- }
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-